
package com.crowdfunding.circle.index.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.crowdfunding.circle.activity.entity.ActivityInfoVO;
import com.crowdfunding.circle.activity.param.ActivityInfoParam;
import com.crowdfunding.circle.activity.service.ActivityInfoService;
import com.crowdfunding.circle.common.controller.BaseController;
import com.crowdfunding.circle.data.entity.DataPlatformVO;
import com.crowdfunding.circle.data.param.DataPlatformParam;
import com.crowdfunding.circle.data.service.DataPlatformService;
import com.crowdfunding.circle.news.entity.NewsInfoVO;
import com.crowdfunding.circle.news.param.NewsInfoParam;
import com.crowdfunding.circle.news.service.NewsInfoService;

/**
 * 首页
 *
 * @author 朱国军
 * @since 1.0
 * @version 2016年4月4日 朱国军
 */
@Controller
public class IndexController extends BaseController {

    @Autowired
    private ActivityInfoService activityInfoService;

    @Autowired
    private NewsInfoService newsInfoService;

    @Autowired
    private DataPlatformService dataPlatformService;
    
    private final static String INDEX_PAGE = "/index";
    
    private final static String ACTIVITY_LIST_PAGE = "/index/index_activity_list";

    /**
     * 首页请求
     *
     * @return 返回首页页面
     */
    @RequestMapping(value = "/")
    public ModelAndView index() {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        
        NewsInfoParam newsInfoParam = new NewsInfoParam();
        newsInfoParam.setPageSize(10);
        newsInfoParam.setPageNo(1);
        newsInfoParam.setNewsStatus(2);
        newsInfoParam.setNewsType(1);
        List<NewsInfoVO> dataList = newsInfoService.queryByPage(newsInfoParam);
        resultMap.put("dataList", dataList);
        resultMap.put("paramMap", newsInfoParam);
        
        ActivityInfoParam activityInfoParam = new ActivityInfoParam();
        activityInfoParam.setPageNo(1);
        activityInfoParam.setPageSize(2);
        List<ActivityInfoVO> activityList = activityInfoService.queryByPage(activityInfoParam);
        resultMap.put("activityList", activityList);
        
        DataPlatformParam platformParam = new DataPlatformParam();
        platformParam.setPageSize(4);
        platformParam.setPageNo(1);
        platformParam.setAuditStatus(2);
        platformParam.setOrderField("t.update_time");
        platformParam.setOrderDirection("DESC");
        List<DataPlatformVO> platformDataList = dataPlatformService.queryByPage(platformParam);
        resultMap.put("platformDataList", platformDataList);

        return new ModelAndView(INDEX_PAGE, resultMap);
    }
    
    @RequestMapping(value = "/uncheck/index/activity/list")
    public ModelAndView queryList(ActivityInfoParam activityInfoParam) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        List<ActivityInfoVO> dataList = activityInfoService.queryByPage(activityInfoParam);
        resultMap.put("dataList", dataList);
        resultMap.put("paramMap", activityInfoParam);
        return new ModelAndView(ACTIVITY_LIST_PAGE, resultMap);
    }
}
